﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MachineBuildingSystem
{
    public partial class DeliveryModifyForm : XtraForm
    {
        //所有车牌号列表
        private string m_HaveCarCodeStr = "";
        //所有司机列表
        private string m_HaveDriverStr = "";

        private string m_CarCode = "";
        public string CarCode
        {
            get { return m_CarCode;}
            set { m_CarCode = value; }
        }

        private string m_Driver = "";
        public string Driver
        {
            get { return m_Driver; }
            set { m_Driver = value; }
        }
        public DeliveryModifyForm()
        {
            InitializeComponent();
        }

        private void DeliveryModifyForm_Load(object sender, EventArgs e)
        {
            mruEditCarCode.Text = m_CarCode;
            mruEditDriver.Text = m_Driver;
            InitMruEditCarCode();
            InitMruEditDriver();
        }

        //初始化司机下拉框
        private void InitMruEditDriver()
        {
            try
            {
                mruEditDriver.Properties.Items.Clear();
                m_HaveDriverStr = ConfigurationManager.AppSettings["Drivers"];
                foreach (string driver in m_HaveDriverStr.Split(','))
                    mruEditDriver.Properties.Items.Add(driver);
            }
            catch (Exception ex)
            {
                LogHelper.error("初始化司机下拉框数据异常：" + ex.Message);
            }
        }

        private void InitMruEditCarCode()
        {
            try
            {
                mruEditCarCode.Properties.Items.Clear();
                m_HaveCarCodeStr = ConfigurationManager.AppSettings["CarCodeStr"];
                foreach (string carCode in m_HaveCarCodeStr.Split(','))
                    mruEditCarCode.Properties.Items.Add(carCode);
            }
            catch (Exception ex)
            {
                LogHelper.error("初始化车牌号下拉框数据异常：" + ex.Message);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            m_CarCode = mruEditCarCode.Text.Trim();
            if (string.IsNullOrEmpty(m_CarCode))
            {
                MessageBox.Show("车牌号不能为空！");
                return;
            }
            m_Driver = mruEditDriver.Text.Trim();
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
